#include "serverUi.h"


int main(int argc, char* argv[])
{
    std::cout << "请使用管理员权限运行程序。" << std::endl << std::endl;
    std::cout << "运行该程序需要参数！请按照要求输入参数。" << std::endl << std::endl;
    std::cout << "-addr\t\tTCP 服务器所需 IP 地址，默认为 127.0.0.1。" << std::endl;
    std::cout << "-port\t\tTCP 服务器所需端口号，默认为 1717。" << std::endl << std::endl;
    
#define CHECK_ARGC if (i >= argc-1) { \
    fprintf(stderr, "not enough arguments for: %s\n", argv[i]); \
    exit(1); \
}

    std::string addr("127.0.0.1");
    uint16_t port(1717);
    for (int i = 1; i < argc; i++)
    {
        if (!strcmp("-addr", argv[i]))
        {
            CHECK_ARGC
            addr = std::string(argv[++i]);
        }
        if (!strcmp("-port", argv[i]))
        {
            CHECK_ARGC
            port = atoi(argv[++i]);
        }
    }

    ServerUI server(addr, port);
    server.run();

    return 0;
}